* Main body of the table produced in Bootstrap_First_Stages.do
* LM and F stats collected from the run below

sort *
cap egen gr_rsjt=group(gr_sjt relational_quartile)
cap egen gr_Rsjt=group(gr_sjt D_sourcing)

* 1: IV, one theta 

qui: capture 
ivreghdfe ln_WR_o ${exogenous}  (${endogenous}=${instrument}) if SAMPLE_THETA==1, abs(${fes}) sfirst savefirst savefprefix(ff_)  cluster(gr_sjt)
capture gen LM_iv=e(idstat)				
capture gen F_iv=e(widstat)				
	  
* 2: Variation of 2 IV with buyer fixed effects

qui: capture 
ivreghdfe ln_WR_o ${exogenous}  (${endogenous}=${instrument}) if SAMPLE_THETA==1, abs(${fes} b_id) sfirst savefirst savefprefix(ff_) cluster(gr_sjt)
capture gen LM_ivbfe=e(idstat)
capture gen F_ivbfe=e(widstat)
	
	
* 3. IV, one theta, instrumenting for fabric as well

qui: capture 
ivreghdfe ln_WR_o   ( ${endogenous} ${exogenous}  = ${instrument} ln_cotton_price_x_rate c.ln_cotton_price_x_rate#i1.numf_orig ) ///
 if SAMPLE_THETA==1, abs(${fes})  sfirst savefirst savefprefix(ff_)  cluster(gr_sjt)
capture gen LM_iv2=e(idstat)
capture gen F_iv2=e(widstat) 

* 4. IV, thetas by buyer relational quartile

capture drop int_exog* int_endog* int_inst*

gen class=(D_sourcing+1)

forvalues i=1(1)2{
capture gen int_exog_`i'=(class==`i')*${exogenous}
capture gen int_endog_`i'=(class==`i')*${endogenous}
capture gen int_instr_`i'=(class==`i')*${instrument}
}

qui: capture  
ivreghdfe ln_WR_o ${exogenous} int_exog_1 ///
 (${endogenous} int_endog_1 = ${instrument} int_instr_1 ) if SAMPLE_THETA==1 & D_sourcing!=., abs(gr_Rsjt) cluster(gr_sjt)  sfirst savefirst savefprefix(ff_)
capture gen LM_ivq=e(idstat)
capture gen F_ivq=e(widstat)

*keep LM_* F_*